home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / PInterfaces / Threads.p < prev    next >
Encoding:
Text File  |  1994-07-17  |  6.7 KB  |  234 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Threads.p
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16.  
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Threads;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __THREADS__}
  27. {$SETC __THREADS__ := 1}
  28.  
  29. {$I+}
  30. {$SETC ThreadsIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33.  
  34. {$IFC UNDEFINED __ERRORS__}
  35. {$I Errors.p}
  36. {$ENDC}
  37. {    ConditionalMacros.p                                            }
  38.  
  39. {$IFC UNDEFINED __MEMORY__}
  40. {$I Memory.p}
  41. {$ENDC}
  42. {    Types.p                                                        }
  43. {    MixedMode.p                                                    }
  44.  
  45. {$PUSH}
  46. {$ALIGN MAC68K}
  47. {$LibExport+}
  48.     
  49. TYPE
  50. ThreadState = INTEGER;
  51.  
  52.  
  53. CONST
  54.     kReadyThreadState            = 0;
  55.     kStoppedThreadState            = 1;
  56.     kRunningThreadState            = 2;
  57.  
  58. { Error codes have been meoved to Errors.(pah) }
  59. { Thread environment characteristics }
  60.     
  61. TYPE
  62. ThreadTaskRef = Ptr;
  63.  
  64. { Thread characteristics }
  65.     ThreadStyle = LONGINT;
  66.  
  67.  
  68. CONST
  69.     kCooperativeThread            = 1 * (2**(0));
  70.     kPreemptiveThread            = 1 * (2**(1));
  71.  
  72. { Thread identifiers }
  73.     
  74. TYPE
  75. ThreadID = LONGINT;
  76.  
  77.  
  78. CONST
  79.     kNoThreadID                    = 0;
  80.     kCurrentThreadID            = 1;
  81.     kApplicationThreadID        = 2;
  82.  
  83. { Options when creating a thread }
  84.     
  85. TYPE
  86. ThreadOptions = LONGINT;
  87.  
  88.  
  89. CONST
  90.     kNewSuspend                    = 0+(1 * (2**(0)));
  91.     kUsePremadeThread            = 0+(1 * (2**(1)));
  92.     kCreateIfNeeded                = 0+(1 * (2**(2)));
  93.     kFPUNotNeeded                = 0+(1 * (2**(3)));
  94.     kExactMatchThread            = 0+(1 * (2**(4)));
  95.  
  96. { Information supplied to the custom scheduler }
  97.  
  98. TYPE
  99.     SchedulerInfoRec = RECORD
  100.         InfoRecSize:            LONGINT;
  101.         CurrentThreadID:        ThreadID;
  102.         SuggestedThreadID:        ThreadID;
  103.         InterruptedCoopThreadID: ThreadID;
  104.     END;
  105.     SchedulerInfoRecPtr = ^SchedulerInfoRec;
  106.  
  107. {
  108.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  109.     of differences between 680x0 and PowerPC runtime architectures with regard to
  110.     the implementation of the Thread Manager.
  111.  }
  112. { Prototype for thread's entry (main) routine }
  113.     ThreadEntryProcPtr = ProcPtr;  { PROCEDURE (threadParam: UNIV Ptr); }
  114.  
  115. { Prototype for custom thread scheduler routine }
  116.     ThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  117.  
  118. { Prototype for custom thread switcher routine }
  119.     ThreadSwitchProcPtr = ProcPtr;  { PROCEDURE (threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr); }
  120.  
  121. { Prototype for thread termination notification routine }
  122.     ThreadTerminationProcPtr = ProcPtr;  { PROCEDURE (threadTerminated: ThreadID; terminationProcParam: UNIV Ptr); }
  123.  
  124. { Prototype for debugger NewThread notification }
  125.     DebuggerNewThreadProcPtr = ProcPtr;  { PROCEDURE (threadCreated: ThreadID); }
  126.  
  127. { Prototype for debugger DisposeThread notification }
  128.     DebuggerDisposeThreadProcPtr = ProcPtr;  { PROCEDURE (threadDeleted: ThreadID); }
  129.  
  130. { Prototype for debugger schedule notification }
  131.     DebuggerThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  132.  
  133. { Thread Manager routines }
  134.  
  135. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  136.     {$IFC NOT GENERATINGCFM}
  137.     INLINE $303C, $0501, $ABF2;
  138.     {$ENDC}
  139. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER): OSErr;
  140.     {$IFC NOT GENERATINGCFM}
  141.     INLINE $303C, $0402, $ABF2;
  142.     {$ENDC}
  143. FUNCTION GetSpecificFreeThreadCount(threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER): OSErr;
  144.     {$IFC NOT GENERATINGCFM}
  145.     INLINE $303C, $0615, $ABF2;
  146.     {$ENDC}
  147. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size): OSErr;
  148.     {$IFC NOT GENERATINGCFM}
  149.     INLINE $303C, $0413, $ABF2;
  150.     {$ENDC}
  151. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT): OSErr;
  152.     {$IFC NOT GENERATINGCFM}
  153.     INLINE $303C, $0414, $ABF2;
  154.     {$ENDC}
  155. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: UNIV Ptr; stackSize: Size; options: ThreadOptions; threadResult: UNIV Ptr; VAR threadMade: ThreadID): OSErr;
  156.     {$IFC NOT GENERATINGCFM}
  157.     INLINE $303C, $0E03, $ABF2;
  158.     {$ENDC}
  159. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: UNIV Ptr; recycleThread: BOOLEAN): OSErr;
  160.     {$IFC NOT GENERATINGCFM}
  161.     INLINE $303C, $0504, $ABF2;
  162.     {$ENDC}
  163. FUNCTION YieldToThread(suggestedThread: ThreadID): OSErr;
  164.     {$IFC NOT GENERATINGCFM}
  165.     INLINE $303C, $0205, $ABF2;
  166.     {$ENDC}
  167. FUNCTION YieldToAnyThread: OSErr;
  168.     {$IFC NOT GENERATINGCFM}
  169.     INLINE $42A7, $303C, $0205, $ABF2;
  170.     {$ENDC}
  171. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID): OSErr;
  172.     {$IFC NOT GENERATINGCFM}
  173.     INLINE $303C, $0206, $ABF2;
  174.     {$ENDC}
  175. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  176.     {$IFC NOT GENERATINGCFM}
  177.     INLINE $303C, $0407, $ABF2;
  178.     {$ENDC}
  179. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  180.     {$IFC NOT GENERATINGCFM}
  181.     INLINE $303C, $0508, $ABF2;
  182.     {$ENDC}
  183. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  184.     {$IFC NOT GENERATINGCFM}
  185.     INLINE $303C, $0512, $ABF2;
  186.     {$ENDC}
  187. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr): OSErr;
  188.     {$IFC NOT GENERATINGCFM}
  189.     INLINE $303C, $0209, $ABF2;
  190.     {$ENDC}
  191. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: UNIV Ptr; inOrOut: BOOLEAN): OSErr;
  192.     {$IFC NOT GENERATINGCFM}
  193.     INLINE $303C, $070A, $ABF2;
  194.     {$ENDC}
  195. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: UNIV Ptr): OSErr;
  196.     {$IFC NOT GENERATINGCFM}
  197.     INLINE $303C, $0611, $ABF2;
  198.     {$ENDC}
  199. FUNCTION ThreadBeginCritical: OSErr;
  200.     {$IFC NOT GENERATINGCFM}
  201.     INLINE $303C, $000B, $ABF2;
  202.     {$ENDC}
  203. FUNCTION ThreadEndCritical: OSErr;
  204.     {$IFC NOT GENERATINGCFM}
  205.     INLINE $303C, $000C, $ABF2;
  206.     {$ENDC}
  207. FUNCTION SetDebuggerNotificationProcs(notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  208.     {$IFC NOT GENERATINGCFM}
  209.     INLINE $303C, $060D, $ABF2;
  210.     {$ENDC}
  211. FUNCTION GetThreadCurrentTaskRef(VAR threadTRef: ThreadTaskRef): OSErr;
  212.     {$IFC NOT GENERATINGCFM}
  213.     INLINE $303C, $020E, $ABF2;
  214.     {$ENDC}
  215. FUNCTION GetThreadStateGivenTaskRef(threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  216.     {$IFC NOT GENERATINGCFM}
  217.     INLINE $303C, $060F, $ABF2;
  218.     {$ENDC}
  219. FUNCTION SetThreadReadyGivenTaskRef(threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  220.     {$IFC NOT GENERATINGCFM}
  221.     INLINE $303C, $0410, $ABF2;
  222.     {$ENDC}
  223.  
  224. {$ALIGN RESET}
  225. {$POP}
  226.  
  227. {$SETC UsingIncludes := ThreadsIncludes}
  228.  
  229. {$ENDC} {__THREADS__}
  230.  
  231. {$IFC NOT UsingIncludes}
  232.  END.
  233. {$ENDC}
  234.